package com.auth.controller;

import com.auth.model.BsRoles;
import com.auth.service.BsRolesService;
import com.exception.bean.Result;
import com.exception.enu.ExceptionEnum;
import com.exception.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2017/8/21 0021.角色控制层
 */
@RestController
public class BsRolesController {
    @Autowired
    private BsRolesService bsRolesService;

    /**
     * 保存角色
     * @param name 名称
     * @param describe 描述
     * @param userId 用户ID
     * @param unitiId 单位ID
     * @return
     * @throws Exception
     */
    @PostMapping("role/save")
    public Result saveRole(String name,String describe,String userId,String unitiId) throws Exception{
        BsRoles bsRoles=new BsRoles(UUID.randomUUID().toString().trim(),name.trim(),describe.trim(),userId,null,unitiId);
        int i=  bsRolesService.createRoles(bsRoles);
       return i>0?ResultUtil.success():ResultUtil.error(ExceptionEnum.UNKNOW_ERROR);
    }

    /**
     * 跟新角色
     * @param bsRoles 角色类
     * @return
     * @throws Exception
     */
    @PostMapping("role/update")
    public Result updateRole(BsRoles bsRoles) throws Exception{
        return ResultUtil.success(bsRolesService.updateRoles(bsRoles));
    }

    /**
     * 查询角色
     * @param pageNum 页数
     * @param pageSize 行数
     * @return
     * @throws Exception
     */
    @PostMapping("role/find-all-page")
    public Result findAllPage(int pageNum,int pageSize) throws Exception{
        return ResultUtil.success(bsRolesService.findAll(pageNum,pageSize));
    }

    /**
     * 删除角色
     * @param id 角色ID
     * @return
     * @throws Exception
     */
    @PostMapping("role/delet")
    public Result deleteRoles(String id) throws Exception{
        return ResultUtil.success(bsRolesService.deleteRoles(id));
    }
}
